﻿using PMS.Core.Caching;

namespace PMS.Services.EntityServices
{
    /// <summary>
    /// 所有缓存Key统一配置，方便管理
    /// </summary>
    public static partial class CacheKeyConfigs
    {
        #region Store mappings

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : entity ID
        /// {1} : entity name
        /// </remarks>
        public static CacheKey StoreMappingIdsByEntityIdNameCacheKey => new CacheKey("PMS.storemapping.ids.entityid-name-{0}-{1}");

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : entity ID
        /// {1} : entity name
        /// </remarks>
        public static CacheKey StoreMappingsByEntityIdNameCacheKey => new CacheKey("PMS.storemapping.entityid-name-{0}-{1}");

        /// <summary>
        /// Gets a key pattern to clear cache
        /// </summary>
        public static string StoreMappingsPrefixCacheKey => "PMS.storemapping.";
        #endregion

        #region StoreCacheKeys
        /// <summary>
        /// Gets a key for caching
        /// </summary>
        public static CacheKey StoresAllCacheKey => new CacheKey("PMS.stores.all");

        #endregion

        #region SettingCacheKeys
        /// <summary>
        /// Gets a key for caching
        /// </summary>
        public static CacheKey SettingsAllAsDictionaryCacheKey => new CacheKey("PMS.setting.all.as.dictionary");

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        public static CacheKey SettingsAllCacheKey => new CacheKey("PMS.setting.all");

        /// <summary>
        /// Gets a key pattern to clear cache
        /// </summary>
        public static string SettingsPrefixCacheKey => "PMS.setting.";

        #endregion

        #region Languages
        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : store ID
        /// {1} : show hidden records?
        /// </remarks>
        public static CacheKey LanguagesAllCacheKey => new CacheKey("PMS.language.all-{0}-{1}");

        /// <summary>
        /// Gets a key pattern to clear cache
        /// </summary>
        public static string LanguagesAllPrefixCacheKey => "PMS.language.all";
        #endregion

        #region CustomerCacheKeys & Default Configs
        /// <summary>
        /// Gets a password salt key size
        /// </summary>
        public static int PasswordSaltKeySize => 5;

        /// <summary>
        /// Gets a max username length
        /// </summary>
        public static int CustomerUsernameLength => 20;

        /// <summary>
        /// Gets a default hash format for customer password
        /// </summary>
        public static string DefaultHashedPasswordFormat => "SHA512";

        /// <summary>
        /// Gets default prefix for customer
        /// </summary>
        public static string CustomerAttributePrefix => "customer_attribute_";

        #region Caching defaults

        #region Customer attributes

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        public static CacheKey CustomerAttributesAllCacheKey => new CacheKey("PMS.customerattribute.all");

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : customer attribute ID
        /// </remarks>
        public static CacheKey CustomerAttributeValuesAllCacheKey => new CacheKey("PMS.customerattributevalue.all-{0}");

        #endregion

        #region Customer roles

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : show hidden records?
        /// </remarks>
        public static CacheKey CustomerRolesAllCacheKey => new CacheKey("PMS.customerrole.all-{0}");

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : role type name
        /// </remarks>
        public static CacheKey CustomerRolesByRoleTypeCacheKey => new CacheKey("PMS.customerrole.roletype-{0}");

        /// <summary>
        /// Gets a key pattern to clear cache
        /// </summary>
        public static string CustomerRolesPrefixCacheKey => "PMS.customerrole.";

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : customer identifier
        /// {1} : show hidden
        /// </remarks>
        public static CacheKey CustomerRoleIdsCacheKey => new CacheKey("PMS.customer.customerrole.ids-{0}-{1}");

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : customer identifier
        /// {1} : show hidden
        /// </remarks>
        public static CacheKey CustomerRolesCacheKey => new CacheKey("PMS.customer.customerrole-{0}-{1}");

        /// <summary>
        /// Gets a key pattern to clear cache
        /// </summary>
        public static string CustomerCustomerRolesPrefixCacheKey => "PMS.customer.customerrole";

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : customer identifier
        /// </remarks>
        public static CacheKey CustomerAddressesByCustomerIdCacheKey => new CacheKey("PMS.customer.addresses.by.id-{0}");

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : customer identifier
        /// {1} : address identifier
        /// </remarks>
        public static CacheKey CustomerAddressCacheKeyCacheKey => new CacheKey("PMS.customer.addresses.address-{0}-{1}");

        /// <summary>
        /// Gets a key pattern to clear cache
        /// </summary>
        public static string CustomerAddressesPrefixCacheKey => "PMS.customer.addresses";

        public static CacheKey CustomerOrganizesAllCacheKey => new CacheKey("PMS.customer.organizes.all");
        #endregion

        #region Customer password

        /// <summary>
        /// Gets a key for caching current customer password lifetime
        /// </summary>
        /// <remarks>
        /// {0} : customer identifier
        /// </remarks>
        public static CacheKey CustomerPasswordLifetimeCacheKey => new CacheKey("PMS.customers.passwordlifetime-{0}");

        #endregion

        #endregion

        #endregion

        #region Generic attributes

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : entity ID
        /// {1} : key group
        /// </remarks>
        public static CacheKey GenericAttributeCacheKey => new CacheKey("PMS.genericattribute.{0}-{1}");

        #endregion

        #region EmailMessages
        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : store ID
        /// </remarks>
        public static CacheKey EmailAccountsAllCacheKey => new CacheKey("PMS.emailaccounts.all");

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : store ID
        /// </remarks>
        public static CacheKey EmailMessageTemplatesAllCacheKey => new CacheKey("PMS.email.messagetemplate.all-{0}");
        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : store ID
        /// {1} : account Id
        /// </remarks>
        public static CacheKey SMSMessageTemplatesAllCacheKey => new CacheKey("PMS.sms.messagetemplate.all-{0}-{1}");

        /// <summary>
        /// Gets a key pattern to clear cache
        /// </summary>
        public static string EmailMessageTemplatesAllPrefixCacheKey => "PMS.email.messagetemplate.all";
        public static string SMSMessageTemplatesAllPrefixCacheKey => "PMS.sms.messagetemplate.all";

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : template name
        /// {1} : store ID
        /// </remarks>
        public static CacheKey EmailMessageTemplatesByNameCacheKey => new CacheKey("PMS.email.messagetemplate.name-{0}-{1}");

        public static CacheKey SMSMessageTemplatesByNameCacheKey => new CacheKey("PMS.sms.messagetemplate.name-{0}-{1}");

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : template name
        /// </remarks>
        public static string EmailMessageTemplatesByNamePrefixCacheKey => "PMS.email.messagetemplate.name-{0}";
        public static string SMSMessageTemplatesByNamePrefixCacheKey => "PMS.sms.messagetemplate.name-{0}";
        /// <summary>
        /// 用户短信验证码临时存储：应用场景，短信验证码登录，更换密码等
        /// 后期进行验证码校验
        /// 设置验证码10分钟内有效，避免重复生成新验证码发送
        /// </summary>
        /// <remarks>
        /// {0} : SMSTemplateName
        /// {1} : CustomerId
        /// </remarks>
        public static CacheKey CustomerSMSVerifyCodeCacheKey => new CacheKey("Customer.sms.verifycode-{0}-{1}", 10);
        /// <summary>
        /// 用户邮箱验证码临时存储：应用场景，更换邮箱地址
        /// 后期进行验证码校验
        /// 设置验证码为默认60分钟内有效，避免重复生成新验证码发送
        /// </summary>
        /// <remarks>
        /// {0} : EmailTemplateName
        /// {1} : CustomerId
        /// </remarks>
        public static CacheKey CustomerEmailVerifyCodeCacheKey => new CacheKey("Customer.email.verifycode-{0}-{1}", 10);
        #endregion

        #region SystemModules
        /// <summary>
        /// Gets a key for caching all systemodules
        /// </summary>
        /// <remarks>
        /// {0} : store ID
        /// </remarks>
        public static CacheKey SystemModulesAllCacheKey => new CacheKey("PMS.systemmodules.menus.all-{0}");

        /// <summary>
        /// Gets a key for caching all systemodules by Customer
        /// </summary>
        /// <remarks>
        /// {0} : customer ID
        /// </remarks>
        public static CacheKey CustomerSystemModulesCacheKey => new CacheKey("PMS.systemmodules.menus.customer-{0}");
        /// <summary>
        /// Gets a key for caching all systemodules by CustomerRole
        /// </summary>
        /// <remarks>
        /// {0} : customer Role ID
        /// </remarks>
        public static CacheKey SystemModulesByCustomerRoleCacheKey => new CacheKey("PMS.systemmodules.menus.customerrole-{0}");
        /// <summary>
        /// Gets a key for caching all systemodule-customerrole mappings by CustomerRole
        /// </summary>
        /// <remarks>
        /// {0} : customer Role ID
        /// </remarks>
        public static CacheKey ModuleRoleMappingsByCustomerRoleCacheKey => new CacheKey("PMS.systemmodule-customerrole-mappings-roleid-{0}");
        /// <summary>
        /// Gets a key for caching all systemodule-customerrole mappings by SystemModuleId
        /// </summary>
        /// <remarks>
        /// {0} : system module ID
        /// </remarks>
        public static CacheKey ModuleRoleMappingsByModuleIdCacheKey => new CacheKey("PMS.systemmodule-customerrole-mappings-moduleid-{0}");
        /// <summary>
        /// Gets a key pattern to clear systemodule-customerrole mappings  cache
        /// </summary>
        public static string ModuleRoleMappingsAllPrefixCacheKey => "PMS.systemmodule-customerrole-mappings";
        /// <summary>
        /// Gets a key pattern to clear cache
        /// </summary>
        public static string SystemModulesAllPrefixCacheKey => "PMS.systemmodules.menus";
        /// <summary>
        /// Gets a key for caching all modulebuttons
        /// </summary>
        public static CacheKey ModuleButtonsAllCacheKey => new CacheKey("PMS.systemmodules.buttons.all");
        /// <summary>
        /// Gets a key for systemmodule assigned buttons
        /// </summary>
        /// <remarks>
        /// {0} : SystemModule Id
        /// </remarks>
        public static CacheKey ModuleAssignedButtonsCachKey => new CacheKey("PMS.systemmodules.buttons.moduleassginedbtns-{0}");
        #endregion

        #region MediaData_CacheKey
        /// <summary>
        /// Gets a key for caching all mimetypes
        /// </summary>
        public static CacheKey MimeTypesAllCacheKey => new CacheKey("PMS.media.mimetypes.all");
        #endregion

        #region AreaSelect_CacheKey
        /// <summary>
        /// Gets a key for caching all area json data
        /// </summary>
        public static CacheKey AreaJsonDataAllCacheKey => new CacheKey("PMS.areajson.all");
        public static string AreaGzipDataFilePath => "~/App_Data/area.json.gz";
        #endregion

        #region Access control list
        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : entity ID
        /// {1} : entity name
        /// </remarks>
        public static CacheKey AclRecordByEntityIdNameCacheKey => new CacheKey("PMS.aclrecord.entityid-name-{0}-{1}");
        #endregion

        #region NaviMenus
        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// </remarks>
        public static CacheKey NaviMenuGroupsAllCacheKey => new CacheKey("PMS.navimenu.menugroups.All");

        public static string NaviMenuLayoutTemplatesPrefix => "PMS.navimenu.layouttemplate";
        /// <summary>
        /// Gets a key for caching
        /// </summary>
        public static CacheKey NaviMenuLayoutTemplatesAllCacheKey => new CacheKey("PMS.navimenu.layouttemplate.all");

        /// <summary>
        /// Cache NaviMenuTemplates for each Navimenu identified by each navimnu id
        /// </summary>
        /// <remarks>
        /// {0} : navimenu ID
        /// </remarks>
        public static CacheKey NaviMenuLayoutTemplatesPerMenuCacheKey => new CacheKey("PMS.navimenu.layouttmplate.menuid-{0}");

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : current store ID
        /// {1} : roles of the current user
        /// {2} : MenuGroup
        /// {3} : show hidden?
        /// </remarks>

        public static CacheKey NaviMenusAllCacheKey => new CacheKey("PMS.navimenu.all-{0}-{1}-{2}-{3}");

        /// <summary>
        /// Gets a key pattern to clear cache
        /// </summary>
        public static string NaviMenusAllPrefixCacheKey => "PMS.navimenu.all";

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : parent NaviMenu ID
        /// {1} : show hidden records?
        /// {2} : current customer ID
        /// {3} : store ID
        /// </remarks>
        public static CacheKey NaviMenusByParentNaviMenuIdCacheKey => new CacheKey("PMS.navimenu.byparent-{0}-{1}-{2}-{3}");
       
        /// <summary>
        /// Gets a key pattern to clear cache
        /// </summary>
        /// <remarks>
        /// {0} : parent navimenu ID
        /// </remarks>
        public static string NaviMenusByParentNaviMenuPrefixCacheKey => "PMS.navimenu.byparent-{0}";

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : parent navimenu id
        /// {1} : roles of the current user
        /// {2} : current store ID
        /// {3} : show hidden records?
        /// </remarks>
        public static CacheKey NaviMenusChildIdentifiersCacheKey => new CacheKey("PMS.navimenu.childidentifiers-{0}-{1}-{2}-{3}");

        /// <summary>
        /// Gets a key pattern to clear cache
        /// </summary>
        /// <remarks>
        /// {0} : parent navimenu ID
        /// </remarks>
        public static string NaviMenusChildIdentifiersPrefixCacheKey => "PMS.navimenu.childidentifiers-{0}";

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        public static CacheKey NaviMenusAllDisplayedOnHomepageCacheKey => new CacheKey("PMS.navimenu.homepage.all");

        /// <summary>
        /// Gets a key for caching
        /// </summary>
        /// <remarks>
        /// {0} : current store ID
        /// {1} : roles of the current user
        /// </remarks>
        public static CacheKey NaviMenusDisplayedOnHomepageWithoutHiddenCacheKey => new CacheKey("PMS.navimenu.homepage.withouthidden-{0}-{1}");

        /// <summary>
        /// Gets a key pattern to clear cache
        /// </summary>
        public static string NaviMenusDisplayedOnHomepagePrefixCacheKey => "PMS.navimenu.homepage";

        /// <summary>
        /// Key for caching of category breadcrumb
        /// </summary>
        /// <remarks>
        /// {0} : category id
        /// {1} : roles of the current user
        /// {2} : current store ID
        /// {3} : language ID
        /// </remarks>
        public static CacheKey NaviMenuBreadcrumbCacheKey => new CacheKey("PMS.navimenu.breadcrumb-{0}-{1}-{2}-{3}");

        /// <summary>
        /// Gets a key pattern to clear cache
        /// </summary>
        public static string NaviMenuBreadcrumbPrefixCacheKey => "PMS.navimenu.breadcrumb";

        /// <summary>
        /// Key for categories caching for ui presentation
        /// </summary>
        /// <remarks>
        /// {0} : show hidden records?
        /// {1} : MenuGroup
        /// </remarks>
        public static CacheKey UINaviMenuListKey => new CacheKey("PMS.navimenu.ui-presentation.list-{0}-{1}");
        public static string UINaviMenuPrefixCacheKey => "PMS.navimenu.ui-presentation.list";

        #endregion
    }
}
